import argparse
import matplotlib
import matplotlib.pyplot as plt

def parse_coord(coord_str)->tuple[float, float]:
    """解析坐标字符串"""
    try:
        return tuple(map(float, coord_str.split(',')))
    except:
        raise argparse.ArgumentTypeError("坐标格式应为 '经度,纬度'")

def plot_cross_section(file_list: list[str], var_list: list[str], lon_name: str, lat_name: str, depth_name: str, time_name: str,
                       point1: tuple[float, float], point2: tuple[float, float], time_index: int = 0, vmin: float = None, vmax: float = None,
                       n_levels: int = 10, sigma: float = 1.0, trim_empty_depth: bool = True)->str:
    """
    绘制NetCDF断面图（支持标量和矢量）
    自动根据断面方向选择横坐标（经度或纬度）
    """
    try:
        plt.rcParams["font.family"] = "SimHei"
        plt.rcParams["font.size"] = 12
        # matplotlib.use('TkAgg')
        matplotlib.use('Agg')
        
        print(f"输入参数: {file_list}, {var_list}, {lon_name}, {lat_name}, {depth_name}, {time_name}, {point1}, {point2}, {time_index}, {vmin}, {vmax}, {n_levels}, {sigma}, {trim_empty_depth}")
       
        # 模拟一张绘图
        plt.figure(figsize=(10, 8))
        plt.plot([point1[0], point2[0]], [point1[1], point2[1]], 'k-', linewidth=2)
        plt.plot([point1[0], point2[0]], [point1[1], point2[1]], 'ko', markersize=8)
        plt.title("模拟断面图")
        plt.xlabel("经度")
        plt.ylabel("纬度")
        plt.grid(True)

        plt.savefig("cross_section.png")
        # plt.show()
        return "cross_section.png"
    except Exception as e:
        print(f"Python error occurred: {e}")
        raise  # 确保将异常重新抛出
    finally:
        plt.close()

if __name__ == "__main__":
    pass